package com.efast.dmom.mes.datahandlers.entity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.efast.cafe.util.SpringUtils;
import com.efast.dmom.mes.bean.OperationWorkorder;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.OperationWorkorderDao;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;
@Transactional
@Component
public class OperationWorkorderHandler {
	@Autowired
	private OperationWorkorderDao operationWorkorderDao;
	
	public ResultBean insert (OperationWorkorder operationWorkorder) {
		ResultBean result = new ResultBean(true);
		operationWorkorder.setCreateTime(TimeUtil.getLocalDateTime());
		operationWorkorder.setCreateUser(SpringWebUtils.getRequestUser());
		int insert = operationWorkorderDao.insertSelective(operationWorkorder);
		if (insert > 0) {
			result.setSuccess(false);
			result.setMessage("新增失败");
			
		}
		return result;
	}
	
	public ResultBean batchInsert (List<OperationWorkorder> list) {
		ResultBean result = new ResultBean(true);
		list.forEach(item -> {
			item.setCreateTime(TimeUtil.getLocalDateTime());
			item.setCreateUser(SpringWebUtils.getRequestUser());
			operationWorkorderDao.insertSelective(item);
		});
		return result;
	}
	
	
	
}
